require "Common/EnumConst"
require "Battle/Entity/Entity"
require "Battle/FightEntity"
require "Battle/Entity/PetEntity"
require "Battle/Manager/SpineEffectManager"
require "Battle/BattleScene"

--- @class FightClientManager
FightClientManager = ClientFight.CreateClass("FightClientManager")
local this = FightClientManager
local debug = nil;
local aiDebug = nil;
this.fight = {};
this.frameInfo = {};
this.summonList = {};
--[[
* 初始化战斗
*
* @param team0
* @param team1
*/]]
addOverload(this, "init", function(battleInfo, calHeroCombinationForce)
    local fight = Fight.New();
    fight.fightType = battleInfo.fightType;--这一行要放在最前面
    local sites = this.getSites(fight);
    local sitesPuppet = this.getSitesPuppet(fight);
    fight.fightSites = sites;
    fight.fightSitesPuppet = sitesPuppet;
    fight.debug = debug;
    fight.aiDebug = aiDebug;
    fight.fightId = battleInfo.fightId;
    fight.randomSeed = battleInfo.randSeed;
    --math.randomseed(fight.randomSeed:reverse():sub(1, 7))
    --fight.random = (math.random());

    --计算羁绊组合奖励
    this.calHeroCombination(fight, battleInfo.atkTeam);
    if (calHeroCombinationForce or battleInfo.calDefTeamHeroCombination or battleInfo.fightType == FightTypeConst.GUILD_BATTLE) then
        this.calHeroCombination(fight, battleInfo.fefTeam);
    end

    fight.teams[1] = this.createFightTeam(fight, 1, battleInfo.atkTeam);
    fight.teams[2] = this.createFightTeam(fight, 2, battleInfo.defTeam);

    fight.hitrate_suppress = battleInfo.hitrateSuppress;
    fight.damage_suppress = battleInfo.damageSuppress;

    local maxBattleSeconds = battleInfo.maxBattleSeconds > 0 and battleInfo.maxBattleSeconds or ClientFight.Global.MAX_FIGHT_SECONDS;
    fight.maxFrame = maxBattleSeconds * 1000 / ClientFight.Global.FIGHT_FRAME;
    fight.reportSaveTypeEnum = battleInfo.reportSaveTypeEnum;
    --SkillRoleMgr.savePathFile( getJsonStr(battleInfo));
    this.fight = fight;
    return fight;
end, "table", "boolean")
--
--addOverload(this, "init", function(fightId, fightType, team0, team1, randomSeed)
--    local battleInfo = BattleInfo.New();
--    battleInfo.atkTeam = team0;
--    battleInfo.defTeam = team1;
--    battleInfo.randSeed = tostring(os.time());
--    return this.init(battleInfo);
--end, "string", "number", "table", "table", "number")

function this.initFighter(fight, fighter)
    -- 初始开始血量
    if (fighter.hp <= 0) then
        fighter.hp = ClientFight.FighterAttributeManager.getFightAttr(fighter, FighterAttributeEnum.HP);
    end

    -- 初始化普通攻击;
    local normalSkillId = fighter.heroBean.f_HeroAtk;
    fighter.normalAttack = ClientFight.SkillClientManager.createFightSkill(fight, normalSkillId, fighter);

    local skills = {};
    local skillUnlockBean1 = ClientFight.DataManager.getSkillUnlockBean(fighter.modelId, fighter.level, fighter.star, 1);
    if (skillUnlockBean1 ~= nil) then
        table.insert(skills, skillUnlockBean1);
    end
    local skillUnlockBean2 = ClientFight.DataManager.getSkillUnlockBean(fighter.modelId, fighter.level, fighter.star, 2);
    if (skillUnlockBean2 ~= nil) then
        table.insert(skills, skillUnlockBean2);
    end
    local skillUnlockBean3 = ClientFight.DataManager.getSkillUnlockBean(fighter.modelId, fighter.level, fighter.star, 3);
    if (skillUnlockBean3 ~= nil) then
        table.insert(skills, skillUnlockBean3);
    end
    local skillUnlockBean4 = ClientFight.DataManager.getSkillUnlockBean(fighter.modelId, fighter.level, fighter.star, 4);
    if (skillUnlockBean4 ~= nil) then
        table.insert(skills, skillUnlockBean4);
    end
    local skillUnlockBean5 = ClientFight.DataManager.getSkillUnlockBean(fighter.modelId, fighter.level, fighter.star, 5);
    if (skillUnlockBean5 ~= nil) then
        table.insert(skills, skillUnlockBean5);
    end
    local skillUnlockBean0 = ClientFight.DataManager.getSkillUnlockBean(fighter.modelId, fighter.level, fighter.star, 0);--额外隐藏学会的一个技能
    if (skillUnlockBean0 ~= nil) then
        table.insert(skills, skillUnlockBean0);
    end

    local skillIdList = {};
    if (fighter.addSkills ~= nil) then
        -- 其他系统附加技能
        for key, entry in pairs(fighter.addSkills) do

            table.insert(skillIdList, key);
        end
    end

    -- 初始化可以使用技能
    local maxEnergy = 0;
    for i, skillBean in pairs(skills) do

        local skill = ClientFight.SkillClientManager.addSkill(fight, fighter, skillBean.skillId, skillBean.skillType);
        if (skill ~= nil) then
            local energy = skill.skillBean.f_UseSP;
            if (energy > maxEnergy) then
                maxEnergy = energy;
            end
        end
    end
    for i, skillId in pairs(skillIdList) do

        if (skillId ~= 0) then
            local skill = ClientFight.SkillClientManager.addSkill(fight, fighter, skillId, 0);
            if (skill ~= nil) then
                local energy = skill.skillBean.f_UseSP;
                if (energy > maxEnergy) then
                    maxEnergy = energy;
                end
            end
        end
    end

    -- 排序
    table.sort(fighter.skills, function(o1, o2)
        if (o1.skillBean.f_SkillPriority > o2.skillBean.f_SkillPriority) then
            return true;
        elseif (o1.skillBean.f_SkillPriority < o2.skillBean.f_SkillPriority) then
            return false;
        end
        return true;
    end);

    fighter.maxEnergy = maxEnergy;
end
--[[
* 战斗开始
*
* @param fight
*/]]
function this.start(fight)
    -- 进入战场，站位
    enter(fight);
    local fighterList = {}
    for i = 1, table.getn(fight.teams) do
        local fighters = fight.teams[i].fighters;
        for i, fighter in pairs(fighters) do
            LogUtil.info(fight, function()
                return "[" .. fight.frame .. "][INIT]Fighter " .. fighter.fighterId .. " 初始化" ..
                        fighter.position .. " teamIndex:" .. fighter.teamIndex
            end);
            --fighter.skills().forEach(s -> LogUtil.info("[" ..  fight.frame .. "][INIT]Fighter " ..  fighter.fighterId .. " 初始化技能" ..  sskillBean.f_SkillID));
            table.insert(fighterList, ReportManager.fighterToJsonString(fight, fighter, 0));
            table.insert(fight.actions, ReportManager.fighterToJsonString(fight, fighter, 0));

            ClientFight.FighterManager.addPassiveSkillEffect(fight, fighter);
            if (not fighter:isDie() and fighter.puppet ~= nil) then
                table.insert(fighterList, ReportManager.fighterToJsonString(fight, fighter.puppet, 0))
                table.insert(fight.actions, ReportManager.fighterToJsonString(fight, fighter.puppet, 0));

                ClientFight.FighterManager.addPassiveSkillEffect(fight, fighter.puppet);
            end
        end
        local alternates = fight.teams[i].alternates;
        for i, fighter in pairsByKeys(alternates) do
            local frameInfoCommand = ReportManager.intSceneToJsonString(fight, fighter);
            table.insert(fighterList, frameInfoCommand)
            table.insert(fight.actions, frameInfoCommand);

        end
        --table.insert(fight.actions, frameInfoCommand)
        --FightManager.playActions(frameInfoCommand)
    end
    --初始化替补
    for i, v in pairs(this.summonList) do
        local param = {};
        table.insert(fighterList, ReportManager.summonToJsonString(fight, param.modelId, true));
        table.insert(fight.actions, ReportManager.summonToJsonString(fight, param.modelId, true));
    end
    FightManager.initFighterList = {};
    for i, v in pairs(fighterList) do
        FightManager.reportReport(v)
    end
    -- 将team的initSkill加到所有人身上
    for i = 1, table.getn(fight.Teams) do
        local fighters = fight.teams[i].fighters;
        for k, fighter in pairs(fighters) do
            ClientFight.FighterManager.addInitFightPassiveSkillEffect(fight, fighter);
        end
    end

    -- fight.getCmds()
    -- .add(InitCmd.builder().fight(JSON.parseObject(JSON.toJSONString(fight),
    -- Fight.class)).build());
    -- 战斗未结束
    --while fight.finish == 0 do
    --    -- 帧计算战斗
    --    this.frame(fight);
    --end
    --[[
        for i = 1, table.getn(fight.teams) do
            for j = 1, table.getn(fight.teams[i].fighters) do
                local fighter = fight.teams[i].fighters[j];
                if (fighter.moveTarget ~= nil or fighter.moveDirection ~= 0 or fighter.movePosition ~= nil) then
                    -- 停止移动
                    fighter.moveTarget = nil;
                    fighter.moveDirection = 0;
                    fighter.movePosition = nil;
                    ReportManager.setMoveEndToJsonString(fight, fighter, fighter.moveAction);
                    fighter.moveAction = nil;

                    SkillRoleMgr.savePathFile("[" ..  fight.frame .. "][STOP]Fighter " ..  fighter.fighterId .. " 停止移动" ..  getJsonStr(fighter.position));
                end
            end
        end
    ]]

    -- fight.getCmds().add(EndCmd.builder().fight(fight).build());
    --} finally {
    --LogUtil.closeLog(fight);
    --AILogUtil.closeLog(fight);
    --}
end
---@param fight Fight
function this.enter(fight)
    -- 玩家队伍站位
    for i = 1, 2 do
        local sum = 0;
        local fighters = fight.teams[i].fighters;
        for j, fighter in pairs(fighters) do

            local pos = fight.fightSites[i][fighter.site];
            fighter.position = Vector2.New(pos[1], pos[3]);
            if (not fighter:isDie()) then
                --统计未死亡的人数
                sum = sum + 1;
                this.beforEntryScene(fighter);
            end
        end
        if (sum == 0) then
            --全死光了, 替补直接上场
            ClientFight.FighterManager.alternateReady(fight, i, 1, ClientFight.Global.FIGHTER_DIE_TIME + 2);
        end
    end
end

function this.beforEntryScene(fighter)
    ClientFight.FighterManager.beforeEnterScene(fighter);
end
function this.getSites(fight)
    local fightType = fight.fightType;
    if (fightType == ClientFight.FightTypeConst.UNION_BOSS_FIGHT) then
        return ClientFight.Global.FIGHT_SITES_UNION;
    elseif (fightType == ClientFight.FightTypeConst.ARENA) then
        return ClientFight.Global.FIGHT_SITES_FOR7;
    else
        return ClientFight.Global.FIGHT_SITES;
    end
end
function this.getSitesPuppet(fight)
    local fightType = fight.fightType;
    if (fightType == ClientFight.FightTypeConst.UNION_BOSS_FIGHT) then
        return ClientFight.Global.FIGHT_SITES_UNION;
    else
        if (fightType == ClientFight.FightTypeConst.ARENA) then
            return ClientFight.Global.FIGHT_SITES_FOR7;
        else
            return ClientFight.Global.FIGHT_SITES;
        end
    end
end

function this.cutInFrame(fight)
    --fight.actionSkills = {};
    --table.addAllToArr(fight.actionSkills, fight.skills)
    --for i, skill in pairsByKeys(fight.actionSkills) do
    --    if(skill.skill.skillBean.f_PrepareTime)then
    --    ClientFight.SkillClientManager.frame(skill);
    --    end
    --end


end


--[[
* 帧事件
*
* @param fight
*/]]
---@param fight Fight
function this.frame(fight, frame)
    if fight.finish ~= 0 then
        FightManager.addEndCommandInfo()
        return {}
    end
    if table.getn(fight.frozenSkills) ~= 0 then
        -- 技能计算
        fight.actionSkills = {};
        fight.actionSkills = fight.frozenSkills;
        for i, skill in pairs(fight.actionSkills) do
            SkillRoleMgr.savePathFile(string.format("[%s][SKILL]%s执行黑屏时间逻辑,技能frame:%s", skill.fight.frame, skill.skill.skillBean.f_SkillID, skill.frame));
            ClientFight.SkillClientManager.frame(skill);
        end
        return ;
    end

    fight.frame = frame;--fight.frame + 1;
    -- 到达狂暴时间
    if (fight.frame > fight.maxFrame) then
        fight.finish = 1;
        return ;
    end

    -- 触发帧开始事件
    for i = 1, table.getn(fight.teams) do
        for j = 1, table.getn(fight.teams[i].fighters) do
            local fighter = fight.teams[i].fighters[j];
            if (not fighter:isDie()) then
                -- 触发帧开始事件
                ClientFight.EventManager.notifyEventListener(fight, FightEventEnum.FRAME_START, fighter.fighterId);
            end
        end
    end

    -- 执行帧事件
    if (fight.events[fight.frame]) then
        local events = fight.events[fight.frame];
        fight.events[fight.frame] = nil
        for i, event in pairs(events) do
            event();
        end
    end

    -- 技能计算
    fight.actionSkills = {};
    table.addAllToArr(fight.actionSkills, fight.skills)
    for i, skill in pairsByKeys(fight.actionSkills) do
        ClientFight.SkillClientManager.frame(skill);
    end

    local frozen = false;
    for i = 1, table.getn(fight.teams) do
        for idx = 1, table.getn(fight.teams[i].fighters) do
            local fighter = fight.teams[i].fighters[idx];
            if fighter.modelId == 1 then
                local a = 0;
            end
            -- 未死亡计算AI
            if (not fighter:isDie() and fighter.aiTree ~= nil) then
                fighter.aiTree.root:tick();
            end

            -- 计算召唤无过期
            if (fighter:isSummons()) then
                ClientFight.FighterManager.checkSummonTime(fight, fighter);
            end

            if (table.getn(fight.frozenSkills) ~= 0) then

                frozen = true;
                break ;
            end

        end

        if (frozen) then
            break ;
        end

        --		  -- 计算援助AI
        --		  fight.getAiFighters().clear();
        --		  fight.getAiFighters().addAll(fight.getTeams()[i].getAlternates());
        --		  for (Fighter fighter : fight.getAiFighters()) {
        --			  -- 未死亡计算AI
        --			  if (!ClientFight.FighterManager:isDie(fighter) and fighter.getAiTree() ~= nil) {
        --				  fighter.getAiTree().getRoot().tick();
        --			  }
        --			  if(!fight.getFrozenSkills().isEmpty()) {
        --				  frozen = true;
        --				  break;
        --			  }
        --		  }
        --
        --		  if(frozen) {
        --			  break;
        --		  }

        -- 计算其他单位
        for j = 1, table.getn(fight.teams[i].others) do
            local fighter = fight.teams[i].others[j];
            -- 未死亡计算AI
            if (not fighter:isDie() and fighter.aiTree ~= nil) then
                fighter.aiTree.root:tick();
            end

            if (#fight.frozenSkills > 0) then
                frozen = true;
                break ;
            end
        end

        if (frozen) then
            break ;
        end
    end

    -- 触发帧结束事件
    for i = 1, table.getn(fight.teams) do
        for j = 1, table.getn(fight.teams[i].fighters) do
            local fighter = fight.teams[i].fighters[j];
            if (fighter:isDie()) then
                goto continue;
            end
            -- 触发帧结束事件
            ClientFight.EventManager.notifyEventListener(fight, FightEventEnum.FRAME_END, fighter.fighterId);
            :: continue ::
        end
    end

    return frameInfo;
end

function this.playOverHitSkill(modelId, team)
    for i = 1, table.getn(fight.teams) do
        for j = 1, table.getn(fight.teams[i].fighters) do
            local fighter = fight.teams[i].fighters[j];
            if (fighter:isDie()) then
                goto continue;
            end
            :: continue ::

        end
    end
end

--[[
* 创建战斗队伍
*/]]
function this.createFightTeam(fight, index, team)
    local fightTeam =  ClientFight.FightTeam.New();
    fightTeam.teamIndex = index;
    fightTeam.frozen = team.frozen;
    fightTeam.professionAdditionMap = team.professionAdditionMap;
    fightTeam.professionAmountMap = team.professionAmountMap;
    fightTeam.heroSkillAi = team.heroSkillAi;
    for i = 1, table.getn(team.members) do
        local member = team.members[i];
        local petSkillId = nil
        if (i == 0 and table.getn(team.petSkillIdList) ~= 0) then
            petSkillId = team.petSkillIdList;
        end
        local fighter = this.createFighter(fight, fightTeam, member, petSkillId);
        if (fighter.site >= 1 and fighter.site <= table.getn(fight.fightSites[index])) then
            table.insert(fightTeam.fighters, fighter);
        else
            fighter.assistant = true;
            table.insert(fightTeam.alternates, fighter);
            --local frameInfoCommand = ReportManager.enterSceneToJsonString(fight, fighter.puppet);
            --table.insert(fight.actions, frameInfoCommand)
            --FightManager.playActions(frameInfoCommand)
        end
    end

    for i = 1, table.getn(team.initSkills) do
        fightTeam.fighters[1].addSkills[team.initSkills[i]] = 1;
    end

    if (team.supportSkillId > 0 and fight.fightType ~= ClientFight.FightTypeConst.UNION_BOSS_FIGHT) then
        fightTeam.supportSkill(ClientFight.SkillClientManager.createFightSkill(fight, team.supportSkillId, nil));
    end

    this.initTeamFighter(fight, fightTeam);

    return fightTeam;
end

function this.initTeamFighter(fight, fightTeam)
    local fighter = Fighter.New();
    fighter.fight = fight;
    fighter.fightTeam = fightTeam;
    fighter.teamIndex = fightTeam.teamIndex;
    fighter.fighterId = fight.ids;
    fight.ids = fight.ids + 1;
    -- 位置设置到左右边界的y轴中心点
    local y = (ClientFight.Global.FIGHT_INNER_ROUND[1][3] + ClientFight.Global.FIGHT_INNER_ROUND[2][3]) / 2;
    local x = 0;
    if (fightTeam.teamIndex == 0) then
        x = ClientFight.Global.FIGHT_INNER_ROUND[1][1];
    else
        x = ClientFight.Global.FIGHT_INNER_ROUND[2][1];
    end
    fighter.position = Vector2.New(x, y);
    fighter.heroBean = ClientFight.DataManager.t_heroBeanMap[9999];
    ClientFight.FighterAttributeManager.initTeamFighterAttribute(fight, fighter);
    fighter.hp = ClientFight.FighterAttributeManager.getFightAttr(fighter, FighterAttributeEnum.HP.id);
    fightTeam.teamFighter = fighter;
    local frameInfoCommand = ReportManager.fighterToJsonString(fight, fighter, 1);
    table.insert(fight.actions, frameInfoCommand)
    FightManager.playActions(frameInfoCommand)
    fighter.modelId = 9999;
    return fighter;
end
--[[
* 创建战斗者
*/]]
function this.createFighter(fight, fightTeam, member, petSkillId)
    local fighter = Fighter.New();
    fighter.fight = fight;
    fighter.fightTeam = fightTeam;
    fighter.teamIndex = fightTeam.teamIndex;
    fighter.fighterId = fight.ids;
    fight.ids = fight.ids + 1;
    fighter.partnerId = member.partnerId;
    fighter.monster = member.monster;
    fighter.leader = member.leader;
    fighter.assistant = member.assistant;
    fighter.weather = member.weather;
    fighter.modelId = member.partnerModelId;
    fighter.level = member.level;
    fighter.skin = member.skinUse;
    fighter.star = member.star;
    fighter.weaponLevel = member.weaponLevel;
    fighter.addSkills = member.addSkills;
    fighter.energy = member.initEnergy;
    fighter.hp = member.initHp;
    fighter.site = member.site;
    fighter.buffDynamicParam = member.buffDynamicParam;
    if (table.getn(petSkillId) > 0) then
        if (fighter.addSkills == nil) then
            fighter.addSkills = {};
        end
        for i, integer in pairs(petSkillId) do
            fighter.addSkills[integer] = integer;
        end
    end

    if (member.attributeMap ~= nil) then
        for key, entry in pairs(member.attributeMap) do

            local values = entry;
            local attributes = {};
            attributes = clone(entry);
            fighter.attributes[key] = ClientFight.BaseAttribute.New(attributes);
        end
    end

    -- 英雄配置
    fighter.heroBean = ClientFight.DataManager.t_heroBeanMap[tonumber(fighter.modelId)];
    -- 体型
    fighter.shape = Rectangle2.New(fighter.heroBean.f_HeroSize);
    -- 警戒范围1
    if (fighter.heroBean.f_WarningRange1 ~= nil) then
        fighter.alertRange1 = Rectangle2.New(fighter.heroBean.f_WarningRange1);
    end
    -- 警戒范围2
    if (fighter.heroBean.f_WarningRange2 ~= nil) then
        fighter.alertRange2 = Rectangle2.New(fighter.heroBean.f_WarningRange2);
    end

    -- 初始化所有战斗者属性
    ClientFight.FighterAttributeManager.initFighterAttribute(fight, fighter);

    -- 初始化战斗者
    this.initFighter(fight, fighter);

    -- 构造行为树
    fighter.aiTree = ClientFight.BehaviourTreesBuilder:build(fight, fighter, FighterAiConstans.fighterAIObj);

    this.afterCreateFighter(fighter, member);
    FightManager.fighterAndEntityList[fighter.fighterId] = fighter;
    return fighter;
end

function this.afterCreateFighter(fighter, member)
    if (fighter.modelId == 61 and member.partnerId > 0) then
        this.afterCreateLijiya(fighter, member);
    end
end

--创建丽姬娅之后
function this.afterCreateLijiya(fighter, member)
    local xizeHeroId = 610;
    local fightTeam = fighter.fightTeam;
    local heroSkillAiBean = fightTeam.heroSkillAi[fighter.modelId];
    if (heroSkillAiBean ~= nil) then
        fightTeam.heroSkillAi[xizeHeroId] = heroSkillAiBean;
    end

    fighter.modelId = xizeHeroId;
    -- 英雄配置
    fighter.heroBean = ClientFight.DataManager.t_heroBeanMap[fighter.modelId];
    -- 体型
    fighter.shape = Rectangle2.New(fighter.heroBean.f_HeroSize);
    -- 警戒范围1
    if (fighter.heroBean.f_WarningRange1 ~= nil) then
        fighter.alertRange1 = Rectangle2.New(fighter.heroBean.f_WarningRange1);
    end
    -- 警戒范围2
    if (fighter.heroBean.f_WarningRange2 ~= nil) then
        fighter.alertRange2(Rectangle2.New(fighter.heroBean.f_WarningRange2));
    end

    local partnerId = member.partnerId;
    local partnerModelId = member.partnerModelId;
    local addSkills = member.addSkills;
    member.partnerId = 0;
    member.partnerModelId = 611;
    member.addSkills = {};
    local puppet = this.createFighter(fighter.fight, fighter.fightTeam, member, nil);
    member.partnerId = partnerId;
    member.partnerModelId = partnerModelId;
    member.addSkills = addSkills;
    puppet.partnerId = 0;
    fighter.puppet = puppet;
end


--[[
* 计算英雄羁绊技能
*/]]
function this.calHeroCombination(fight, team)
    if fight.fightType == ClientFight.FightTypeConst.UNION_BOSS_FIGHT then
        return ;
    end

    --组合  key:组合id,组合数量
    local combinationMap = {};
    --组合  key:组合id,组合数量(势力羁绊)
    local combination2Map = {};
    ---@type table<number, table<number,TeamMember>>
    local fightersByCombinationId = {};
    local fightersByCombinationId2 = {};
    for key, member in pairs(team.members) do
        ---@type HeroCombinationShowTemplate
        local combinationShowTemplate = ClientFight.DataManager.heroCombinationShowTemplateMap[member.partnerModelId];
        local heroBean = DataManager.t_heroBeanMap[member.partnerModelId];
        local is = true;
        if (combinationShowTemplate == nil or heroBean == nil) then
            is = false;
        end
        if is then
            for k, i in pairs(combinationShowTemplate.combinationId) do
                local amount = combinationMap[i] or 0;
                combinationMap[i] = amount + 1;
                local key = fightersByCombinationId[i]
                if (key == nil) then
                    key = {};
                    fightersByCombinationId[i] = key;
                end
                table.insert(key, member)
            end
            local combinationId2 = combinationShowTemplate.combinationId2;
            if combinationId2 == nil then
                combinationId2 = {}
            end
            for k, i in pairs(combinationId2) do
                local amount2 = combination2Map[i] or 0;
                combination2Map[i] = amount2 + 1;
                if fightersByCombinationId2[i] == nil then
                    local param = {}
                    table.insert(param, member)
                    fightersByCombinationId2[i] = param;
                end
            end
        end
    end

    for key, entry in pairs(combinationMap) do
        local combinationTemplate = ClientFight.DataManager.heroCombinationTemplateMap[key];
        if (combinationTemplate == nil or combinationTemplate.f_Block == 1) then
            goto continue
        end
        local amount = entry;
        if (amount < table.getn(combinationTemplate.combinationHero)) then
            goto continue
        end

        local fighters = team.members;
        for i, ints in pairs(combinationTemplate.combinationSkill) do

            for i, member in pairs(fighters) do

                if (ints[1] == 0) then
                    member.addSkills[ints[2]] = ints[2];
                    --                        log.info(member.getPartnerId() .. "增加技能" ..  ints[2]);
                end
                if (ints[1] > 0 and member.partnerModelId == ints[1]) then
                    member.addSkills[ints[2]] = ints[2];
                    --                        log.info(member.getPartnerId() .. "增加技能" ..  ints[2]);
                    break ;
                end
            end
        end
        :: continue ::
    end
    for k, value in pairs(combination2Map) do
        local combinationTemplate = dataManager.heroCombinationTemplateMap[k];
        if (combinationTemplate == nil
                or combinationTemplate.f_Block == 1
                or table.getn(combinationTemplate.combinationFaction) <= 0) then
            goto continue;
        end
        local amount = value;
        if (amount < combinationTemplate.combinationFaction[2]) then
            goto continue;
        end

        local fighters = team.members;
        for i, ints in pairs(combinationTemplate.combinationSkill) do
            for idx, member in pairs(fighters) do
                if (ints[2] == 0) then
                    member.addSkills[ints[2]] = ints[2];
                end
                if (ints[2] > 0 and member.partnerModelId == ints[2]) then
                    member.addSkills[ints[2]] = ints[2];
                    break ;
                end
            end
        end
        :: continue ::
    end

end


function FightClientManager.addSummonList(id)
    if this.summonList[id] then
        this.summonList[id] = id;
    end

end